package com.lkm.asking.controller;


import com.lkm.asking.entity.Data;
import com.lkm.asking.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    private DataService dataService;

    @ResponseBody
    @PostMapping("/insert")
    public String insert(Data data){
        System.out.println(data.getSchool());
        dataService.insert(data);

        return "success";
    }

    @ResponseBody
    @GetMapping("/select")
    public List<Data> select(String userName) {
        //System.out.print(userName);
        return dataService.listData(userName);
    }

    @ResponseBody
    @GetMapping("/selectByKind")
    public List<Data> selectByKind(String bookmark) {
        return dataService.listDataByKind(bookmark);
    }

    @ResponseBody
    @GetMapping("/delete")
    public int delete(int id) {
        return dataService.delData(id);
    }

    @ResponseBody
    @GetMapping("/addOne")
    public int addOne(int id) {
        return dataService.addOne(id);
    }

    @ResponseBody
    @GetMapping ("/addRead")
    public int addRead(int id) {
        System.out.print(id);
        return dataService.addRead(id);
    }

    @ResponseBody
    @GetMapping("/decOne")
    public int decOne(int id){return  dataService.decOne(id);}

    @ResponseBody
    @PostMapping("/listDataBySchool")
    public List<Data> listDataBySchool(String school) {
        return dataService.listDataBySchool(school);
    }


    @ResponseBody
    @PostMapping("/selectByID")
    public List<Data> selectByID(Integer id) {
        return dataService.listDataByID(id);
    }

}
